Passed
Push — master ( 20c00a...9a7ed1 )
by Rafael S.
01:38
created

64-bit.js ➔ describe(ꞌ64-bit to bytesꞌ)   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 62

Duplication

Lines 62
Ratio 100 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
c 1
b 0
f 0
nc 1
nop 0
dl 62
loc 62
rs 9.4743

13 Functions

Rating   Name   Duplication   Size   Complexity  
A 64-bit.js ➔ ... ➔ it(ꞌshould turn 2 64-bit floats to 16 bytes (-1, 1)ꞌ) 4 4 1
A 64-bit.js ➔ ... ➔ it(ꞌshould turn 1 64-bit floats to 8 bytes (0.5)ꞌ) 4 4 1
A 64-bit.js ➔ ... ➔ it(ꞌshould turn 1 64-bit floats to 16 bytes hex (-0.5)ꞌ) 4 4 1
A 64-bit.js ➔ ... ➔ it(ꞌshould turn 1 64-bit floats to 16 bytes hex (-1)ꞌ) 4 4 1
A 64-bit.js ➔ ... ➔ it(ꞌshould turn 1 64-bit float to 8 bytes (-0.5)ꞌ) 4 4 1
A 64-bit.js ➔ ... ➔ it(ꞌshould turn 3 64-bit floats to 16 bytes (0 1 0)ꞌ) 4 4 1
A 64-bit.js ➔ ... ➔ it(ꞌshould turn 3 64-bit floats to 16 bytes (0 0 1)ꞌ) 4 4 1
A 64-bit.js ➔ ... ➔ it(ꞌshould turn 2 64-bit floats to 16 bytes (0s)ꞌ) 4 4 1
A 64-bit.js ➔ ... ➔ it(ꞌshould turn 1 64-bit float to 8 bytes (1)ꞌ) 4 4 1
A 64-bit.js ➔ ... ➔ it(ꞌshould turn 1 64-bit float to 8 bytes (pi)ꞌ) 4 4 1
A 64-bit.js ➔ ... ➔ it(ꞌshould turn 1 64-bit float to 8 bytes (hex) (0)ꞌ) 4 4 1
A 64-bit.js ➔ ... ➔ it(ꞌshould turn 1 64-bit float to 8 bytes hex (2)ꞌ) 4 4 1
A 64-bit.js ➔ ... ➔ it(ꞌshould turn 1 64-bit float to 8 bytes (14)ꞌ) 4 4 1

How to fix   Long Method   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
2 View Code Duplication
var assert = require('assert');
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated in your project.
Loading history...
3
4
describe('64-bit to bytes', function() {
5
    
6
    let byteData = require('../../index.js');
7
8
    // 64-bit / 8 bytes
9
    it('should turn 2 64-bit floats to 16 bytes (-1, 1)', function() {
10
        assert.deepEqual(byteData.toBytes([1,-1], 64, {"base": 10}),
11
            [0,0,0,0,0,0,240,63,0,0,0,0,0,0,240,191]);
12
    });
13
    it('should turn 1 64-bit floats to 16 bytes hex (-1)', function() {
14
        assert.deepEqual(byteData.toBytes([-1], 64, {"base": 16}),
15
            ['00','00','00','00','00','00','f0','bf']);
16
    });
17
    it('should turn 1 64-bit floats to 16 bytes hex (-0.5)', function() {
18
        assert.deepEqual(byteData.toBytes([-0.5], 64, {"base": 16}),
19
            ['00','00','00','00','00','00','e0','bf']);
20
    });
21
    it('should turn 2 64-bit floats to 16 bytes (0s)', function() {
22
        assert.deepEqual(byteData.toBytes([0, 0], 64, {"base": 10}),
23
            [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]);
24
    });
25
    it('should turn 3 64-bit floats to 16 bytes (0 0 1)', function() {
26
        assert.deepEqual(byteData.toBytes([0, 0, 1], 64, {"base": 10}),
27
            [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,240,63]);
28
    });
29
    it('should turn 3 64-bit floats to 16 bytes (0 1 0)', function() {
30
        assert.deepEqual(byteData.toBytes([0, 1, 0], 64, {"base": 10}),
31
            [0,0,0,0,0,0,0,0,0,0,0,0,0,0,240,63,0,0,0,0,0,0,0,0]);
32
    });
33
    it('should turn 1 64-bit floats to 8 bytes (0.5)', function() {
34
        assert.deepEqual(byteData.toBytes([0.5], 64, {"base": 10}),
35
            [0,0,0,0,0,0,224,63]);
36
    });
37
    it('should turn 1 64-bit float to 8 bytes (-0.5)', function() {
38
        assert.deepEqual(byteData.toBytes([-0.5], 64, {"base": 10}),
39
            [0,0,0,0,0,0,224,191]);
40
    });
41
    it('should turn 1 64-bit float to 8 bytes (pi)', function() {
42
        assert.deepEqual(byteData.toBytes([3.141592653589793], 64, {"base": 10}),
43
            [24,45,68,84,251,33,9,64]);
44
    });
45
    it('should turn 1 64-bit float to 8 bytes (pi)', function() {
46
        assert.deepEqual(byteData.toBytes([9], 64, {"base": 10}),
47
            [0,0,0,0,0,0,34,64]);
48
    });
49
    it('should turn 1 64-bit float to 8 bytes (14)', function() {
50
        assert.deepEqual(byteData.toBytes([31.41592653589793], 64, {"base": 10}),
51
            [94,56,85,41,122,106,63,64]);
52
    });
53
    it('should turn 1 64-bit float to 8 bytes (1)', function() {
54
        assert.deepEqual(byteData.toBytes([314159265358979.3], 64, {"base": 10}),
55
            [53,72,162,118,158,219,241,66]);
56
    });
57
    it('should turn 1 64-bit float to 8 bytes (hex) (0)', function() {
58
        assert.deepEqual(byteData.toBytes([0], 64, {"base": 16}),
59
            ["00","00","00","00","00","00","00","00"]);
60
    })
61
    it('should turn 1 64-bit float to 8 bytes hex (2)', function() {
62
        assert.deepEqual(byteData.toBytes([2], 64, {"base": 16}),
63
            ["00","00","00","00","00","00","00","40"]);
64
    });
65
});
66